import java.io.File;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

public class Demo {
	public static void main(String argv[]) {
		try{
			DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
			DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
			
			//root element
			Document doc = docBuilder.newDocument();
			Element rootElement = doc.createElement("company");
			doc.appendChild(rootElement);
			
			//staff element
			Element staff = doc.createElement("staff");
			rootElement.appendChild(staff);
			
			//thiet lap attributs cho staff element
			Attr attr = doc.createAttribute("id");
			attr.setValue("1");
			staff.setAttributeNode(attr);
			
			//cach khac
			//staff.setAttribute("id", "1");
			
			// firstname element
			Element firstname = doc.createElement("firstname");
			firstname.appendChild(doc.createTextNode("son"));
			staff.appendChild(firstname);
			
			//lastname element
			Element firstname = doc.createElement("lastname");
			firstname.appendChild(doc.createTextNode("hoang hong"));
			staff.appendChild(lastname);
		}
		catch(){}
		
	}
}
